home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Development / RxMUI / Examples / EmCheck.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  2004-01-31  |  7.3 KB  |  246 lines

  1. /* EMCheck 1.2 (13.3.2001) - Checks emails */
  2.  
  3. signal on halt
  4. signal on break_c
  5.  
  6. call Init()
  7. call CreateApp()
  8. call HandleApp()
  9. /* never reached */
  10. /***************************************************************************/
  11. Init:procedure expose global.
  12.     l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  13.     if AddLibrary("rexxsupport.library","rxmui.library","rxsocket.library","rxlibnet.library")~=0 then exit
  14.     call RxMUIOpt("DebugMode ShowErr")
  15.  
  16.     global.MacroNotify="EMCHECK_"time(s)
  17.     global.mns=MacroNotifyCreate(global.MacroNotify)
  18.     if global.mns=0 then exit
  19.  
  20.     return
  21. /***************************************************************************/
  22. HandleApp: procedure expose global.
  23.  
  24.     ctrl_c=2**12
  25.     mask=or(global.mns,ctrl_c)
  26.  
  27.     do forever
  28.         call NewHandle("app","h",mask)
  29.  
  30.         if and(h.signals,ctrl_c)>0 then exit
  31.         if and(h.signals,global.mns)>0 then call HandleMacroEvent()
  32.  
  33.         if h.EventFlag then
  34.             select
  35.                 when h.event="QUIT" then exit
  36.                 otherwise interpret h.event
  37.             end
  38.  
  39.     end
  40.     /* never reached */
  41. /***********************************************************************/
  42. HandleMacroEvent: procedure expose global.
  43.     do forever
  44.         ev=MacroNotifyGetEvent(global.MacroNotify)
  45.         if ev="" then return
  46.  
  47.         parse var ev ev child d
  48.         select
  49.  
  50.             when ev="STARTED" then do
  51.                 call set("g1","ActivePage",1)
  52.                 call set("app","sleep",0)
  53.             end
  54.  
  55.             when ev="ENDED" then do
  56.                 call set("g1","ActivePage",0)
  57.             end
  58.  
  59.             when ev="INFO" then do
  60.                 call info(d)
  61.             end
  62.  
  63.             otherwise nop
  64.         end
  65.     end
  66.     /* never reached */
  67. /***********************************************************************/
  68. CreateApp: procedure expose global.
  69.  
  70.     mstrip.0="MProject"
  71.      MProject.class="menu"
  72.      MProject.title="Project"
  73.       MProject.0=MenuItem("MAbout","About...","?")
  74.       MProject.1=MenuItem("MAboutRxMUI","About RxMUI...")
  75.       MProject.2=MenuItem("MAboutMUI","About MUI...")
  76.       MProject.3=MenuItem("","BAR")
  77.       MProject.4=MenuItem("MHide","Hide","H")
  78.       MProject.5=MenuItem("","BAR")
  79.       MProject.6=MenuItem("MQuit","Quit","Q")
  80.     mstrip.1="MSettings"
  81.      MSettings.class="menu"
  82.      MSettings.title="Preferences"
  83.       MSettings.0=MenuItem("MUse","Use","U")
  84.       MSettings.1=MenuItem("MSave","Save","S")
  85.       MSettings.2=MenuItem("MRestore","Last saved","R")
  86.       MSettings.3=MenuItem("","BAR")
  87.       MSettings.4=MenuItem("MMUI","MUI...")
  88.     res=NewObj("menustrip","mstrip")
  89.     if res>0 then exit
  90.  
  91.     app.title="EMCheck"
  92.     app.version="$VER: EMCheck 1.1 (11.11.2000)"
  93.     app.copyright="Under GNU public licence"
  94.     app.author="Alfonso [alfie] Ranieri"
  95.     app.description="Checks a pop3 email account."
  96.     app.base="EMCHECK"
  97.     app.DiskObject="emcheck"
  98.     app.MenuStrip="mstrip"
  99.     app.SubWindow="mwin"
  100.  
  101.      mwin.ID="MAIN"
  102.      mwin.Title="EMCheck 1.1"
  103.      mwin.Contents="mgroup"
  104.  
  105.       mgroup.0="g0"
  106.        g0.Class="group"
  107.        g0.Frame="group"
  108.        g0.Background="groupback"
  109.        g0.Columns=2
  110.         g0.0=label("_Host")
  111.         g0.1="hg"
  112.          hg.Class="group"
  113.          hg.Horiz=1
  114.          hg.spacing=1
  115.            host.CycleChain=1
  116.            host.ObjectID=1
  117.           hg.0=string("host","h")
  118.            HostPort.Weight=30
  119.            HostPort.CycleChain=1
  120.            HostPort.ObjectID=2
  121.            HostPort.IsNumeric=1
  122.            HostPort.MinVal=1
  123.            HostPort.MaxVal=65535
  124.            HostPort.Format="right"
  125.           hg.1=string("HostPort",,110)
  126.         g0.2=label("_Login")
  127.          login.CycleChain=1
  128.          login.ObjectID=3
  129.         g0.3=string("login","l")
  130.         g0.4=label("_Pass")
  131.          pass.CycleChain=1
  132.          pass.ObjectID=4
  133.          pass.Secret=1
  134.         g0.5=string("pass","p")
  135.  
  136.       mgroup.1=text("info","Welcome to EMCheck!")
  137.  
  138.       mgroup.2="g1"
  139.        g1.Class="group"
  140.        g1.PageMode=1
  141.          start.CycleChain=1
  142.         g1.0=button("start","_Start")
  143.          stop.CycleChain=1
  144.         g1.1=button("stop","_Stop")
  145.  
  146.     res=NewObj("application","app")
  147.     if res>0 then exit
  148.  
  149.     call notify("mwin","CloseRequest",1,"app","ReturnID","QUIT")
  150.  
  151.     call notify("MAbout","MenuTrigger","EveryTime","app","About","mwin")
  152.     call notify("MAboutRxMUI","MenuTrigger","EveryTime","app","AboutRxMUI","mwin")
  153.     call notify("MAboutMUI","MenuTrigger","EveryTime","app","AboutMUI","mwin")
  154.     call notify("MHide","MenuTrigger","EveryTime","app","set","iconified",1)
  155.     call notify("MQuit","MenuTrigger","EveryTime","app","returnid","quit")
  156.     call notify("MUse","MenuTrigger","EveryTime","app","save","env")
  157.     call notify("MSave","MenuTrigger","EveryTime","app","save","envarc")
  158.     call notify("MSave","MenuTrigger","EveryTime","app","save","env")
  159.     call notify("MRestore","MenuTrigger","EveryTime","app","load","envarc")
  160.     call notify("MMUI","MenuTrigger","EveryTime","app","OpenConfigWindow")
  161.  
  162.     call notify("start","pressed",0,"app","return","call SafeStart")
  163.     call notify("stop","pressed",0,"app","return","call SafeQuit(0)")
  164.  
  165.     call notify("g1","ActivePage","EveryTime","g0","set","disabled","TriggerValue")
  166.     call notify("g1","ActivePage",0,"mwin","set","DefaultObject","start")
  167.     call notify("g1","ActivePage",1,"mwin","set","DefaultObject","stop")
  168.     call notify("g1","ActivePage",0,"mwin","set","ActiveObject","start")
  169.     call notify("g1","ActivePage",1,"mwin","set","ActiveObject","stop")
  170.  
  171.     call DoMethod("app","load","env")
  172.  
  173.     call set("mwin","open",1)
  174.  
  175.     call set("g1","ActivePage",0)
  176.  
  177.     return
  178. /***************************************************************************/
  179. halt:
  180. break_c:
  181.     call SafeQuit(1)
  182. /***************************************************************************/
  183. SafeStart: procedure expose global.
  184.  
  185.     if ~IsLibOn("SOCKET") then do
  186.         call info("No TCP/IP stack running !!!")
  187.         return
  188.     end
  189.  
  190.     if ~exists("EMCheckFun.rexx") then do
  191.         call info("EMCheckFun.rexx not found !!!")
  192.         return
  193.     end
  194.  
  195.     var.host=xget("host","contents")
  196.     if var.host="" then do
  197.         call info("Host not supplied.")
  198.         return
  199.     end
  200.  
  201.     var.HostPort=xget("HostPort","contents")
  202.     if var.HostPort="" then do
  203.         call info("Host port not supplied.")
  204.         return
  205.     end
  206.  
  207.     if var.HostPort=0 | var.HostPort>65535 then do
  208.         call info("Host port not valid '"var.HostPort"'.")
  209.         return
  210.     end
  211.  
  212.     var.login=xget("login","contents")
  213.     if var.login="" then do
  214.         call info("Login not supplied.")
  215.         return
  216.     end
  217.  
  218.     var.Pass=xget("pass","contents")
  219.     if var.Pass="" then do
  220.         call info("Password not supplied.")
  221.         return
  222.     end
  223.  
  224.     call set("app","sleep",1)
  225.     call set("g1","ActivePage",1)
  226.     call info("Launching child macro...")
  227.  
  228.     var.MacroNotify=global.MacroNotify
  229.     call StemToVar("var")
  230.  
  231.     call RxsCall("EMCheckFun.rexx")
  232.  
  233.     return
  234. /***************************************************************************/
  235. SafeQuit: procedure expose global.
  236. parse arg e
  237.     if e then exit
  238.     call MacroNotifySync()
  239.     return
  240. /***************************************************************************/
  241. info: procedure expose global.
  242. parse arg msg
  243.     call set("info","contents",msg)
  244.     return
  245. /***************************************************************************/
  246.